package com.haiyou.common.http;

import com.alibaba.fastjson2.JSONObject;
import com.haiyou.common.constants.ErrCode;

/**
 * 
 * 
 * @Description: HttpResult 数据组装工具类
 * @author xingyuan
 * @date 2022年3月12日 上午10:17:35
 */
public class HttpResultUtils {
	
	/**
	 * 失败消息体
	 * @param code
	 * @param msg
	 * @return
	 */
	public static HttpResult failResult(int code,String msg) {
		return HttpResult.builder().code(code)
				.msg(TextMsg.builder().text(msg).build()).build();
	}
	
	/**
	 * 失败消息体
	 * @param code
	 * @param msg
	 * @return
	 */
	public static HttpResult failResult(int code,int text_id,JSONObject text_json) {
		return HttpResult.builder().code(code)
				.msg(TextMsg.builder()
						.text_id(text_id)
						.text_json(text_json)
						.build()).build();
	}
	
	

	/**
	 * 成功消息体构建
	 * @param object
	 */
	public static HttpResult successResult(Object object) {
		return successResult("", object);
	}
	
	public static HttpResult successResult() {
		return successResult("",null);
	}
	

	/**
	 * 成功消息体
	 * @param code
	 * @param msg
	 * @param object
	 */
	public static HttpResult successResult(String msg,Object object) {
		int code = ErrCode.OK;
		return HttpResult.builder().code(code)
			.data(object)
			.msg(TextMsg.builder().text(msg).build()).build();
	}
	
	/**
	 * 成功消息体
	 * @param object
	 * @param text_id
	 * @param text_json
	 * @return
	 */
	public static HttpResult successResult(Object object,int text_id,
			JSONObject text_json) {
		int code = ErrCode.OK;
		return HttpResult.builder().code(code)
				.msg(TextMsg.builder()
						.text_id(text_id)
						.text_json(text_json)
						.build()).build();
	}
	
	
	
}
